package com.ruoyi.doudian.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.doudian.service.DoudianAuthService;
import com.ruoyi.doudian.vo.AccessTokenVO;
import com.ruoyi.system.domain.DoudianUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author X
 * @version 1.0
 * @ClassName AuthController
 * @description
 * @date 2020/11/2
 **/
@RestController
@RequestMapping("/doudian")
public class DoudianAuthController {

    @Autowired
    private DoudianAuthService authService;

    /**
     * 抖店授权
     */
    @GetMapping("/auth")
    public AjaxResult doudianAuth() {
        String url = authService.doudianAuth();
        return AjaxResult.success("url", url);
    }

    /***
     * 获取accessToken
     * @return
     */
    @GetMapping("/getAccessToken")
    public ModelAndView getAccessToken(@RequestParam String code,
                                       @RequestParam String state) {
        AjaxResult ajaxResult = authService.getAccessToken(code, state);
        return new ModelAndView("redirect:http://zs.91gongju.cn/");
    }

    /***
     * 获取用户信息
     * @return
     */
    @GetMapping("/getDoudianUserByUserId")
    public AjaxResult getDoudianUserByUserId(@RequestParam Long userId) {
        DoudianUser doudianUser = authService.getDoudianUserByUserId(userId);
        return AjaxResult.success(doudianUser);
    }
}
